package org.tp;

/* tree implementing a type*/

public class Type {
    
    private Type left;
    private Type right;
    private EnumType type;	
    private Integer integer; // array size
    private String id;

    public Type(Type left, Type right, Integer i, EnumType type) {
	this.left=left;
	this.right=right;
	this.integer=i;
	this.type=type;
    }
    public Type(String left, Type right, Integer i, EnumType type) {
	this.id=left;
	this.right=right;
	this.integer=i;
	this.type=type;
    }
    public Type(String left, EnumType type) {
    	this.id=left;
    	this.right=null;
    	this.type=type;
        }
    public Type(String left, Type right, EnumType type) {
    	this(left,right,0, type);
        }
    
    public Type(Type left, Type right, EnumType type) {
    	this(left,right,0, type);
        }
        
    
    public Type(EnumType type) {
    	this.type=type;
    }
    
    public Type getLeft() {
	return left;
    }
    
    public void setLeft(Type left) {
	this.left = left;
    }
    
    public Type getRight() {
	return right;
    }
    public String getId() {
    	return id;
        }
    
    public void setRight(Type right) {
	this.right = right;
    }
    
    public EnumType getEnumType() {
    	return this.type;
    }
    
    
    public String toString() {
	String result = new String();
	switch (type) {
	case INT:
	case STRING:
	case BOOLEAN:
	case FLOAT:
	case CHAR:
		result += type.toString();break;
	case ARRAY:result += "ARRAY ["+integer+"] OF "+left.toString(); break;
	case POINTER:result += "POINTER OF "+left.toString(); break;
	    //case ERROR:result += "ERROR"; break;
	case TYPEDEF:result += id; break;
	case MAP : 
		result += "MAP"; 
		break;
	case SET: result+= "SET"; break;
	case ENUM: result+="ENUM";break;
	case LIST: result+="LIST" ;break;
	case FOR: result+="for"; break;
	};
	//System.out.println("TYPE :"+result+"\n");
	return result;
    }
}
